package cn.com.hhrcw.wx.web;

import cn.com.hhrcw.entity.CmsChannel;
import cn.com.hhrcw.service.ICmsChannelService;
import cn.com.hhrcw.wx.params.WebTemplateParam;
import cn.com.hhrcw.wx.util.WxTemplateUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
* 微信公众号
*
* @author lixingxing
* @since 2020-11-06
*/
@RestController
@Slf4j
@RequestMapping("/service/wx")
@Api(tags = "微信公众号")
@Validated
public class WxTemplatelController extends JeecgController<CmsChannel, ICmsChannelService> {

    @Autowired
    private WxTemplateUtil wxTemplateUtil;

    @Value("${spring.profiles.active}")
    private String env;

    /**
     * 测试环境
     */
    private static final String TEST = "test";

    /**
     * 开发环境
     */
    private static final String DEV = "dev";

    /**
     * 发送模板
     *
     * @return
     * @WebTemplateParam params 请求参数
     */
    @PostMapping(value = "/sendTemplate")
    @AutoLog("发送模板")
    public Result<Object> sendTemplate(@RequestBody @Valid WebTemplateParam params) {

        if (TEST.equalsIgnoreCase(env) || DEV.equalsIgnoreCase(env)) {
            wxTemplateUtil.sendTemplate("", "");
            return Result.ok();
        } else {
            return Result.error("非开发、测试环境");
        }




    }

}
